package com.zprmb.udzt;

import android.animation.ObjectAnimator;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences.Editor;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.activity.InvestLoginDialog;
import com.zprmb.udzt.activity.V6iNewInvestCoupActivity;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.ExplosionField;
import com.zprmb.udzt.util.GuideAlertDialog;
import com.zprmb.udzt.util.GuideAlertDialog.OnSureClickListener;
import com.zprmb.udzt.util.LogUtils;
import com.zprmb.udzt.util.LoginAlertDialog;
import com.zprmb.udzt.util.NumUtil;
import com.zprmb.udzt.util.Regular;
import com.zprmb.udzt.util.ToastUtil;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.view.LoadingDialog;
import com.zprmb.udzt.view.MyCircle;
import com.zprmb.udzt.view.MyScrollView;

import org.json.JSONObject;

import java.util.List;

public class V6DetailsActivity extends BaseActivity implements
        OnClickListener, OnSureClickListener, InvestLoginDialog.OnSureClickListener {

    // private ViewPager viewPager;// 页卡内容
    private ImageView imageView;// 动画图片
    private int offset = 0;// 动画图片偏移量
    private int currIndex = 0;// 当前页卡编号
    private String name;
    private int bmpW;// 动画图片宽
    private LinearLayout li_top1, li_top2, li_top3;
    private List<View> views;// Tab页面列表
    LinearLayout search01, li_viewpager;
    private View view;
    private String ref = "", linkurl;
    private String investId;
    private String[] data, text;
    // private McoySnapPageLayout mcoySnapPageLayout = null;
    //
    // private McoyProductContentPage bottomPage = null;
    // private McoyProductDetailInfoPage topPage = null;

    private MyScrollView myScrollView;
    private int islogin = 0;
    private MyCircle progress_1, progress_2, progress_3, progress_4;
    private LoadingDialog ld;
    private int searchLayoutTop;
    private RelativeLayout rl_top_layout, rl_back;
    private LinearLayout li_content;
    private ImageView img_share;
    private TextView product_status_date1, product_status_date2,
            product_status_date3, product_status_date4;// 项目日期
    private TextView product_status1, product_status2, product_status3,
            product_status4;// 项目状态
    // 利率 天数 回款类型 是否可用红包标签 是否可用加息券标签，项目总金额，项目起投金额
    private TextView text_rate, text_addrate, text_day, text_back_Type,
            text_isRedpackage, text_iscoupon, text_total_Amount,
            text_minamount;
    // 项目剩余金额
    private TextView text_remainAmount;
    // private View viewbottmo,viewtop;
    private TextView tv_title;
    private String type, loanid;
    private Button btn_invest;
    private String raiseEndDateMMdd;// 项目募集时间（除年）
    private String openTimeMMdd;// 开标时间月日
    private String countRateTime;// 收益起算
    private String dueTime;// 项目到期时间
    private String openTime;// 预期回款时间
    private String raiseEndDateName;// 项目募集名称
    private String countRateTimeName;// 收益起算名称
    private String dueTimeName;// 项目到期名称
    private String openTimeName;// 预期回款名称
    private String currentTime;// 预期回款名称
    private ExplosionField mExplosionField;// 粉碎动画执行方法类
    private ImageView img_project_info, img_project_protocol,
            img_project_record, img_project_problem;
    private LinearLayout li_project_info, li_project_protocol,
            li_project_record, li_project_problem;
    private int progress2;
    private ObjectAnimator anim = null;
    private GuideAlertDialog mAlertDialog;
    LoginAlertDialog mLoginAlertDialog;
    InvestLoginDialog mAlertDialog2;
    //网络优化
    private LinearLayout layout_investdetail;
    //网络优化图片

    private ImageView iv_v4_nonetwork;

    private TextView is_zhekou;

    private boolean flag_zhekou = false;

    //百分号
    private TextView text_baifen;
    //天
    private TextView text_tian;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.v6details_activity);
//        setContentInview2(this).setVisibility(View.INVISIBLE);
//        Toast.makeText(this, "进图到详情了", Toast.LENGTH_SHORT).show();
        setImmersionStatus();

        initIntent();
        initview();
        layout_investdetail = (LinearLayout) findViewById(R.id.layout_investdetail);
        //百分号
        text_baifen = (TextView) findViewById(R.id.text_baifen);
        //天数
        text_tian = (TextView) findViewById(R.id.text_tian);
        iv_v4_nonetwork = (ImageView) findViewById(R.id.iv_v4_nonetwork);

        iv_v4_nonetwork.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
            }
        });
        //抵扣券的控件
        is_zhekou = (TextView) findViewById(R.id.is_zhekou);
        registerBoradcastReceiver();
        if (!network()) {
            layout_investdetail.setVisibility(View.GONE);
            iv_v4_nonetwork.setVisibility(View.VISIBLE);
        } else {
            layout_investdetail.setVisibility(View.VISIBLE);
            iv_v4_nonetwork.setVisibility(View.GONE);
        }

        // initImageView();
    }

    private void initIntent() {
        // TODO Auto-generated method stub
        type = getIntent().getStringExtra("type");
        loanid = getIntent().getStringExtra("id");
        name = getIntent().getStringExtra("name");
        if (getIntent().getStringExtra("investId") != null) {
            investId = getIntent().getStringExtra("investId");
        }
    }

    private void initImageView() {

        bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.a)
                .getWidth();// 获取图片宽度
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenW = dm.widthPixels;// 获取分辨率宽度
        offset = (screenW / 3 - bmpW) / 2;// 计算偏移量
        Matrix matrix = new Matrix();
        matrix.postTranslate(offset, 0);
        imageView.setImageMatrix(matrix);// 设置动画初始位置
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            searchLayoutTop = li_top3.getBottom();// 获取searchLayout的顶部位置
            Log.e("向下的距离", searchLayoutTop + "");

        }
    }

    private void initview() {
        // TODO Auto-generated method stub
        mAlertDialog = new GuideAlertDialog(this, this);

        mAlertDialog2 = new InvestLoginDialog(this, this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText(getIntent().getStringExtra("name"));

        ref = getShare().getString("usercode", "");
        li_top1 = (LinearLayout) findViewById(R.id.li_top1);
        li_top2 = (LinearLayout) findViewById(R.id.li_top2);
        li_top3 = (LinearLayout) findViewById(R.id.li_top3);
        img_share = (ImageView) findViewById(R.id.img_share);
        mExplosionField = ExplosionField.attach2Window(V6DetailsActivity.this);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        rl_top_layout = (RelativeLayout) findViewById(R.id.rl_top_layout);
        btn_invest = (Button) findViewById(R.id.btn_invest);
        myScrollView = (MyScrollView) findViewById(R.id.myScrollView);
        li_viewpager = (LinearLayout) findViewById(R.id.li_viewpager);
        li_content = (LinearLayout) findViewById(R.id.li_content);
        product_status1 = (TextView) findViewById(R.id.product_status1);
        product_status2 = (TextView) findViewById(R.id.product_status2);
        product_status3 = (TextView) findViewById(R.id.product_status3);
        product_status4 = (TextView) findViewById(R.id.product_status4);
        product_status_date1 = (TextView) findViewById(R.id.product_status_date1);
        product_status_date2 = (TextView) findViewById(R.id.product_status_date2);
        product_status_date3 = (TextView) findViewById(R.id.product_status_date3);
        product_status_date4 = (TextView) findViewById(R.id.product_status_date4);
        li_top3 = (LinearLayout) findViewById(R.id.li_top3);
        text_back_Type = (TextView) findViewById(R.id.back_type);
        text_day = (TextView) findViewById(R.id.tv_day);
        text_rate = (TextView) findViewById(R.id.tv_rate);
        text_addrate = (TextView) findViewById(R.id.tv_add_rate);
        text_iscoupon = (TextView) findViewById(R.id.is_coupon);
        text_isRedpackage = (TextView) findViewById(R.id.is_redpackage);
        text_minamount = (TextView) findViewById(R.id.tv_minamount);
        text_remainAmount = (TextView) findViewById(R.id.tv_remainamount);
        text_total_Amount = (TextView) findViewById(R.id.tv_total_money);
        img_project_info = (ImageView) findViewById(R.id.img_project_info);
        img_project_protocol = (ImageView) findViewById(R.id.img_project_protocol);
        img_project_record = (ImageView) findViewById(R.id.img_project_record);
        img_project_problem = (ImageView) findViewById(R.id.img_project_problem);

        // views=new ArrayList<View>();
        // view=getLayoutInflater().inflate(R.layout.pager_view_layout, null);
        // views.add(view);
        // views.add(view);
        // views.add(view);
        // views.add(view);
        img_share.setOnClickListener(this);
//		myScrollView.setOnScrollListener(this);
        // viewPager=(ViewPager) findViewById(R.id.vPager);
        // viewPager.setAdapter(new
        // MyPagerAdapter(getSupportFragmentManager()));

        li_project_info = (LinearLayout) findViewById(R.id.li_project_info);
        li_project_protocol = (LinearLayout) findViewById(R.id.li_project_protocol);
        li_project_record = (LinearLayout) findViewById(R.id.li_project_record);
        li_project_problem = (LinearLayout) findViewById(R.id.li_project_problem);
        li_project_info.setOnClickListener(new MyOnClickListener(0));
        li_project_protocol.setOnClickListener(new MyOnClickListener(1));
        li_project_record.setOnClickListener(new MyOnClickListener(2));
        li_project_problem.setOnClickListener(new MyOnClickListener(3));
        btn_invest.setOnClickListener(this);
        rl_back.setOnClickListener(this);
        progress_1 = (MyCircle) findViewById(R.id.progress_1);
        progress_2 = (MyCircle) findViewById(R.id.progress_2);
        progress_3 = (MyCircle) findViewById(R.id.progress_3);
        progress_4 = (MyCircle) findViewById(R.id.progress_4);

        text_iscoupon.setVisibility(View.GONE);
        text_isRedpackage.setVisibility(View.GONE);


    }

    private void initData() {
        // TODO Auto-generated method stub
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("uplan", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                 /*   setContentInview2(V6DetailsActivity.this).setVisibility(
                            View.VISIBLE);*/
                    // V6DetailsActivity.this.setTh eme(android.R.)
                    // setflip_horizontal_in(V6DetailsActivity.this, li_all);
                    layout_investdetail.setVisibility(View.VISIBLE);
                    iv_v4_nonetwork.setVisibility(View.GONE);
                    if (!jsonObject.optString("data").equals("null")) {
                        JSONObject json1 = jsonObject.optJSONObject("data");
                        JSONObject json2 = json1.optJSONObject("user");
                        text_remainAmount.setText(NumUtil.getQian(json1
                                .optString("remainAmount")));
                        text_minamount.setText(NumUtil.getQian(json1
                                .optString("minAmount")));
                        text_total_Amount.setText(NumUtil.getQian(json1
                                .optString("amount")));
                        text_back_Type.setText(json1
                                .optString("planRepaymentType"));
                        text_day.setText(json1.optString("closourePeriod"));
                        if (json1.optDouble("rateAdd") <= 0) {
                            text_rate.setText(Regular.getDecimalFormatTwo(json1
                                    .optDouble("rate")));
                            text_addrate.setVisibility(View.GONE);
                        } else {
                            text_addrate.setVisibility(View.VISIBLE);
                            text_rate.setText(Regular.getDecimalFormatTwo(json1
                                    .optDouble("rate")
                                    - json1.optDouble("rateAdd")));
                            text_addrate.setText("+"
                                    + Regular.getDecimalFormatTwo(json1
                                    .optDouble("rateAdd")) + "%");
                        }
                 /*       private boolean flag_zhekou = false;
                        is_zhekou = json1.optBoolean("");
                        flag_zhekou = json1.optBoolean("flagRebate");
                        if ()*/
                        flag_zhekou = json1.optBoolean("flagRebate");

                        if (flag_zhekou == true) {
                            is_zhekou.setVisibility(View.VISIBLE);
                        } else {
                            is_zhekou.setVisibility(View.GONE);
                        }

                        //判断是否有抵扣券
                      /*  if (json1.optBoolean("flagRebate")) {
                            is_zhekou.setVisibility(View.VISIBLE);
                        } else {
                            is_zhekou.setVisibility(View.GONE);
                        }*/

                        if (json1.optBoolean("flagCoupon")) {
                            text_iscoupon.setVisibility(View.VISIBLE);
                        } else {
                            text_iscoupon.setVisibility(View.GONE);
                        }
                        if (json1.optBoolean("flagRedpack")) {
                            text_isRedpackage.setVisibility(View.VISIBLE);
                        } else {
                            text_isRedpackage.setVisibility(View.GONE);
                        }
                        if (json2 == null) {
                            islogin = 0;
                        } else {
                            islogin = 1;
                        }
                        raiseEndDateName = json1.optString("raiseEndDateName");// 募集截止名称
                        countRateTimeName = json1
                                .optString("countRateTimeName");// 收益起算名称
                        dueTimeName = json1.optString("dueTimeName");// 项目到期名称
                        openTimeName = json1.optString("openTimeName");// 预期回款名称
                        raiseEndDateMMdd = json1.optString("raiseEndDate");// 募集年月日
                        openTimeMMdd = json1.optString("openTimeMMdd");// 开始年月日
                        countRateTime = json1.optString("countRateTime");// 收益起算时间
                        dueTime = json1.optString("dueTime");// 项目到期时间
                        openTime = json1.optString("openTime");// 预期回款时间
                        currentTime = json1.optString("currentTime");
                        data = new String[]{raiseEndDateMMdd, countRateTime,
                                dueTime, openTime};
                        text = new String[]{raiseEndDateName,
                                countRateTimeName, dueTimeName, openTimeName};
                        product_status1.setText(text[0]);
                        product_status2.setText(text[1]);
                        product_status3.setText(text[2]);
//                        product_status4.setText(text[3]);
                        product_status_date1.setText(data[0]);
                        product_status_date2.setText(data[1]);
                        product_status_date3.setText(data[2]);
                        product_status_date4.setText(data[3]);
                        text_baifen.setVisibility(View.VISIBLE);
                        text_tian.setVisibility(View.VISIBLE);

                        progress_1.dodo(0, 100);
                        progress_2
                                .dodo(0, json1.optInt("raiseEndDateProgress"));
                        progress_3.dodo(0,
                                json1.optInt("countRateTimeProgress"));
                        progress_4.dodo(0, json1.optInt("dueTimeProgress"));

                        if (json1.optString("status").equals("COLLECTING")) {
                            btn_invest.setEnabled(true);

                            btn_invest
                                    .setBackgroundResource(R.drawable.v6_detail_button);
                        } else {

                            btn_invest.setText(json1.optString("statusName"));

                            btn_invest
                                    .setBackgroundResource(R.drawable.v6_detail_unclick);
                            // btn_invest.setEnabled(false);
                            btn_invest.setEnabled(false);
                        }
                        if ("nonArrivalOpenTime".equals(json1.optString("nonArrivalOpenTimeStatus"))) {
                            btn_invest
                                    .setBackgroundResource(R.drawable.v6_detail_unclick);
//							btn_invest.setEnabled(false);
                            btn_invest.setEnabled(false);
                            btn_invest.setText(Regular.getMilliToHour_Min(json1.optString("openTimes")) + "开放");
                        }
                    }
                } else {
                    ToastUtil.showCenterToast(V6DetailsActivity.this,
                            jsonObject.optString("comment"));
                }


            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                layout_investdetail.setVisibility(View.VISIBLE);
                iv_v4_nonetwork.setVisibility(View.GONE);
            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.execute(V6DetailsActivity.this, Constant.URL
                + "/api/v6/render/assetDetail/" + type + "/" + loanid, "");
        LogUtils.e(V6DetailsActivity.this, Constant.URL
                + "/api/v6/render/assetDetail/" + type + "/" + loanid);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        initData();


    }

    public void moren() {
        img_project_info.setSelected(false);
        img_project_protocol.setSelected(false);
        img_project_record.setSelected(false);
        img_project_problem.setSelected(false);
    }

    /**
     * 头标点击监听 3
     */
    private class MyOnClickListener implements OnClickListener {
        private int index = 0;

        public MyOnClickListener(int i) {
            index = i;

        }

        public void onClick(View v) {
            Intent intent = null;
            if (islogin == 0) {
                mAlertDialog.show();
                mAlertDialog.setText("登录后方可查看项目信息");
                mAlertDialog.setTitle("提示");
                mAlertDialog.setType("login");
                mAlertDialog.setButtonCancel("稍后");
                mAlertDialog.setButtonsure("登录");
                return;
            }
            if (index == 0) {

                intent = new Intent(V6DetailsActivity.this,
                        V4WebViewRegisterActivity.class);

                if (TextUtils.isEmpty(investId)) {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=0&investId=" + "");
                } else {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=0&investId="+ investId);
                }


                intent.putExtra("title", name);
                intent.putExtra("type", type);
                intent.putExtra("share", 1);
                intent.putExtra("id", loanid);

                startActivity(intent);

            } else if (index == 1) {
                intent = new Intent(V6DetailsActivity.this,
                        V4WebViewRegisterActivity.class);

                if (TextUtils.isEmpty(investId)) {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=1&investId="+"");
                } else {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=1&investId=" + investId);
                }


                intent.putExtra("title", name);
                intent.putExtra("share", 1);
                startActivity(intent);
            } else if (index == 2) {
                intent = new Intent(V6DetailsActivity.this,
                        V4WebViewRegisterActivity.class);
                intent.putExtra("title", name);
                intent.putExtra("share", 1);

                if (TextUtils.isEmpty(investId)) {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true"+"&productId="+loanid +"&number=2&investId="+"");
                } else {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=2&investId=" + investId);
                }


                startActivity(intent);
            } else if (index == 3) {
                intent = new Intent(V6DetailsActivity.this,
                        V4WebViewRegisterActivity.class);
                intent.putExtra("title", name);
                intent.putExtra("share", 1);
                if (TextUtils.isEmpty(investId)) {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid +"&number=3&investId="+"");
                } else {
                    intent.putExtra("url", "/landing/productIntroForApp?type="
                            + type + "&appversion=true" + "&productId=" + loanid + "&number=3&investId=" + investId);
                }

                startActivity(intent);
            }


        }


    }

    public void OnTabchangeadd1() {

        if (li_content.getParent() != search01) {
            li_viewpager.removeView(li_content);
            search01.addView(li_content);
        } else {
            search01.removeView(li_content);
            li_viewpager.addView(li_content);
        }

    }

    public void OnTabchangeadd2() {

        search01.removeView(li_content);
        li_viewpager.addView(li_content);

    }

    private void setImmersionStatus() {
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            // 透明状态栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明导航栏
            // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

    public class MyOnPageChangeListener implements OnPageChangeListener {

        int one = offset * 2 + bmpW;// 页卡1 -> 页卡2 偏移量 或者int one=screenW / 3;
        int two = one * 2;// 页卡1 -> 页卡3 偏移量

        public void onPageScrollStateChanged(int arg0) {

        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        public void onPageSelected(int arg0) {

        }

    }

    private final String ACTION_NAME = "发送广播";
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(ACTION_NAME)) {
//                Toast.makeText(V6DetailsActivity.this, "处理action名字相对应的广播", 200);

                finish();
            }
        }

    };

    public void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(ACTION_NAME);
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        // TODO Auto-generated method stub
        super.onActivityResult(arg0, arg1, arg2);
        if (arg1 == 5) {
            setResult(5, arg2);
            finish();
        }
    }

    private void checkAuthentication() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                LogUtils.e(V6DetailsActivity.this, jsonObject.toString());
                Intent intent = null;
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");
                    Editor editor = getShare().edit();
                    editor.putString("isNewUser", json.optString("isNewUser"));
                    editor.commit();
                    if ("false".equals(json.optString("bindCard"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先绑定银行卡～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("bindcard");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("绑定银行卡");

                        return;
                    }
                    if ("false".equals(json.optString("payPass"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先设置交易密码～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("password");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("设置交易密码");
                        return;
                    }
                    if ("false".equals(json.optString("isRiskAssessment"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("投资前请先风险测评～");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("ceping");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("风险测评");
                        return;
                    }

        /* intent = new Intent(V6DetailsActivity.this,
                            V6iCoupActivity.class);*/
                    intent = new Intent(V6DetailsActivity.this,
                            V6iNewInvestCoupActivity.class);
                    intent.putExtra("name", name);
                    intent.putExtra("type", type);
                    intent.putExtra("id", loanid);
                    startActivityForResult(intent, 1);
                } else {
                    if ("please login".equals(jsonObject.optString("comment"))) {

                        intent = new Intent(V6DetailsActivity.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
                        intent.putExtra("product", 1);
                        startActivityForResult(intent, 1);
                    }
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                // TODO Auto-generated method stub
                layout_investdetail.setVisibility(View.VISIBLE);
                iv_v4_nonetwork.setVisibility(View.GONE);
            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(V6DetailsActivity.this, Constant.URL + "/apiAccount/checkAuthentication", "");
    }

    private void shareLogin() {
        VolleryUtil vollery = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Log.e("share_biao", jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");
                    // Intent intent = new Intent(V6DetailsActivity.this,
                    // WXEntryActivity.class);
                    // intent.putExtra("sharelink", json1.optString("linkUrl"));
                    // intent.putExtra("description",
                    // json1.optString("description"));
                    // intent.putExtra("title", json1.optString("title"));
                    // intent.putExtra("imgurl", json1.optString("imageUrl"));
                    // startActivity(intent);
                    // LogUtils.e("url", Constant.URL +
                    // "/api/shareProductContent/"
                    // + type + "/" + id);

                    if (ref.equals("")) {
                        linkurl = json1.optString("linkUrl");

                    } else {
                        linkurl = json1.optString("linkUrl") + "?ref=" + ref;

                    }
                    share(V6DetailsActivity.this,
                            json1.optString("description"),
                            json1.optString("title"),
                            linkurl,
                            json1.optString("imageUrl"));
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                layout_investdetail.setVisibility(View.VISIBLE);
                iv_v4_nonetwork.setVisibility(View.GONE);
            }
        };

        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setShow(true);
        vollery.setRequestMethod(0);
        vollery.execute(V6DetailsActivity.this, Constant.URL
                + "/api/shareProductContent/" + type + "/" + loanid, "");
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.btn_invest:
                checkAuthentication();
             /*   Intent intent;
                intent = new Intent(V6DetailsActivity.this,
                        V6iCoupActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("type", type);
                intent.putExtra("id", loanid);
                startActivityForResult(intent, 1);*/
                break;
            case R.id.rl_back:
                finish();
                break;
            case R.id.img_share:
                shareLogin();
                break;
        }
    }

    @Override
    public void onConfirm() {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (mAlertDialog.getType()) {

            case "bindcard":
                intent = new Intent(V6DetailsActivity.this,
                        V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/account/bankcard/bind/view?app=true&appversion=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case "password":
                intent = new Intent(V6DetailsActivity.this,
                        Set_tr_pw.class);
                startActivity(intent);
                break;
            case "ceping":
                Intent intent0 = null;

                intent0 = new Intent(V6DetailsActivity.this, V6WebviewChild.class);
                intent0.putExtra("url", Constant.URL + "h5/assess/index" + "?showHeader=1&app=true&appversion=true&token=");
                // intent0.putExtra("url",
                // "h5/assess/index?showHeader=1"+"?app=true&token=");
                // intent0.putExtra("flag", 1);
                // intent2.putExtra("url",
                // "/h5/messageCenter?app=true&token="+getToken());
                intent0.putExtra("share", 1);
                intent0.putExtra("titleview", 0);
                intent0.putExtra("title", "风险测评");
                startActivity(intent0);
                break;
            case "login":
                intent = new Intent(V6DetailsActivity.this,
                        V6LoginActivity.class);
                intent.putExtra("close", 1);
                intent.putExtra("product", 1);
                startActivityForResult(intent, 1);
                break;
        }
    }

    @Override
    public void onConfirm2() {
        Intent intent = null;
        switch (mAlertDialog2.getType()) {
            case "login":
                intent = new Intent(V6DetailsActivity.this,
                        V6LoginActivity.class);
                intent.putExtra("close", 1);

                startActivityForResult(intent, 1);
                break;

        }
    }

    @Override
    public void onCancle() {
        // TODO Auto-generated method stub

    }
}
